﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Øving3Blackjack
{
    public partial class Form1 : Form
    {
        private Controller controller;

        public Form1()
        {
            controller = new Controller(this);
            InitializeComponent();
            controller.start();
        }

        private void menuNewGame_Click(object sender, EventArgs e)
        {
            if (new NewGameQuery().ShowDialog() == DialogResult.OK)
            {
                controller.newGame();
            }
        }
        private void menu1Deck_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = true;
            menu2Decks.Checked = false;
            menu3Decks.Checked = false;
            menu4Decks.Checked = false;
            menu5Decks.Checked = false;
            menu6Decks.Checked = false;
            menu7Decks.Checked = false;
            menu8Decks.Checked = false;
            controller.changeDecks(1);
        }
        private void menu2Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = true;
            menu3Decks.Checked = false;
            menu4Decks.Checked = false;
            menu5Decks.Checked = false;
            menu6Decks.Checked = false;
            menu7Decks.Checked = false;
            menu8Decks.Checked = false;
            controller.changeDecks(2);
        }
        private void menu3Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = false;
            menu3Decks.Checked = true;
            menu4Decks.Checked = false;
            menu5Decks.Checked = false;
            menu6Decks.Checked = false;
            menu7Decks.Checked = false;
            menu8Decks.Checked = false;
            controller.changeDecks(3);
        }
        private void menu4Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = false;
            menu3Decks.Checked = false;
            menu4Decks.Checked = true;
            menu5Decks.Checked = false;
            menu6Decks.Checked = false;
            menu7Decks.Checked = false;
            menu8Decks.Checked = false;
            controller.changeDecks(4);
        }
        private void menu5Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = false;
            menu3Decks.Checked = false;
            menu4Decks.Checked = false;
            menu5Decks.Checked = true;
            menu6Decks.Checked = false;
            menu7Decks.Checked = false;
            menu8Decks.Checked = false;
            controller.changeDecks(5);
        }
        private void menu6Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = false;
            menu3Decks.Checked = false;
            menu4Decks.Checked = false;
            menu5Decks.Checked = false;
            menu6Decks.Checked = true;
            menu7Decks.Checked = false;
            menu8Decks.Checked = false;
            controller.changeDecks(6);
        }
        private void menu7Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = false;
            menu3Decks.Checked = false;
            menu4Decks.Checked = false;
            menu5Decks.Checked = false;
            menu6Decks.Checked = false;
            menu7Decks.Checked = true;
            menu8Decks.Checked = false;
            controller.changeDecks(7);
        }
        private void menu8Decks_Click(object sender, EventArgs e)
        {
            menu1Deck.Checked = false;
            menu2Decks.Checked = false;
            menu3Decks.Checked = false;
            menu4Decks.Checked = false;
            menu5Decks.Checked = false;
            menu6Decks.Checked = false;
            menu7Decks.Checked = false;
            menu8Decks.Checked = true;
            controller.changeDecks(8);
        }
        private void menuExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        private void menuContents_Click(object sender, EventArgs e)
        {
            
        }
        private void menuAbout_Click(object sender, EventArgs e)
        {
            new About().ShowDialog();
        }
        private void buttonBetPlus5_Click(object sender, EventArgs e)
        {
            controller.changeBet(5);
        }
        private void buttonBetPlus50_Click(object sender, EventArgs e)
        {
            controller.changeBet(50);
        }
        private void buttonBetPlus100_Click(object sender, EventArgs e)
        {
            controller.changeBet(100);
        }
        private void buttonBetMinus5_Click(object sender, EventArgs e)
        {
            controller.changeBet(-5);
        }
        private void buttonBetMinus50_Click(object sender, EventArgs e)
        {
            controller.changeBet(-50);
        }
        private void buttonBetMinus100_Click(object sender, EventArgs e)
        {
            controller.changeBet(-100);
        }
        private void buttonPlay_Click(object sender, EventArgs e)
        {
            controller.play();
        }
        private void panelImage_Paint(object sender, PaintEventArgs e)
        {
            controller.paintCards(sender, e);
        }
        private void buttonHit_Click(object sender, EventArgs e)
        {
            controller.hit();
        }
        private void buttonSurrender_Click(object sender, EventArgs e)
        {
            controller.surrender();
        }
        private void buttonStand_Click(object sender, EventArgs e)
        {
            controller.stand();
        }
        private void buttonDoubleDown_Click(object sender, EventArgs e)
        {
            controller.doubleDown();
        }
        private void buttonSplit_Click(object sender, EventArgs e)
        {
            controller.split();
        }

        public void changeLabelBet(String text)
        {
            labelBet.Text = text;
        }
        public void changeLabelGold(String text)
        {
            labelGold.Text = text;
        }
        public void changeLabelBetMin(String text)
        {
            labelBetMin.Text = text;
        }
        public void changeLabelBetMax(String text)
        {
            labelBetMax.Text = text;
        }
        public void changeLabelResult(String result)
        {
            labelResult.Text = result;
        }
        public void changeLabelOutput(String output)
        {
            labelOutput.Text = output;
        }

        public void updatePanelImage()
        {
            panelImage.Invalidate();
        }

        public void disableBets()
        {
            buttonBetMinus100.Enabled = false;
            buttonBetMinus5.Enabled = false;
            buttonBetMinus50.Enabled = false;
            buttonBetPlus5.Enabled = false;
            buttonBetPlus50.Enabled = false;
            buttonBetPlus100.Enabled = false;
        }
        public void enableBets()
        {
            buttonBetMinus100.Enabled = true;
            buttonBetMinus5.Enabled = true;
            buttonBetMinus50.Enabled = true;
            buttonBetPlus5.Enabled = true;
            buttonBetPlus50.Enabled = true;
            buttonBetPlus100.Enabled = true;
        }
        public void disableActions()
        {
            buttonHit.Enabled = false;
            buttonStand.Enabled = false;
            buttonDoubleDown.Enabled = false;
            buttonSplit.Enabled = false;
            buttonSurrender.Enabled = false;
        }
        public void changeButtonHit(Boolean onOff)
        {
            buttonHit.Enabled = onOff;
        }
        public void changeButtonPlay(Boolean onOff)
        {
            buttonPlay.Enabled = onOff;
        }
        public void changeButtonStand(Boolean onOff)
        {
            buttonStand.Enabled = onOff;
        }
        public void changeButtonDoubleDown(Boolean onOff)
        {
            buttonDoubleDown.Enabled = onOff;
        }
        public void changeButtonSplit(Boolean onOff)
        {
            buttonSplit.Enabled = onOff;
        }
        public void changeButtonSurrender(Boolean onOff)
        {
            buttonSurrender.Enabled = onOff;
        }
        public void openInsuranceQuery()
        {
            if (new InsuranceQuery().ShowDialog() == DialogResult.Yes)
            {
                controller.insurance();
            }
        }

       
    }
}
